<!-- Dom模板 -->
<template>
  <div class="curriculusetadd">
    <!-- Dom内容 -->
    <el-button type="success" class="opensetbtn" @click="openset"
      >返回</el-button
    >
    <p>请填写课程相关信息</p>
    <div class="msglist">
      <div class="left">课程名称</div>
      <div class="right">
        <el-input v-model="course" placeholder="请输入内容"></el-input>
      </div>
    </div>

    <div class="msglist">
      <div class="left">课程封面</div>
      <div class="right">
        <el-upload action="#" list-type="picture-card" :auto-upload="false">
          <i slot="default" class="el-icon-plus"></i>
          <div slot="file" slot-scope="{ file }">
            <img
              class="el-upload-list__item-thumbnail"
              :src="file.url"
              alt=""
            />
            <span class="el-upload-list__item-actions">
              <span
                class="el-upload-list__item-preview"
                @click="handlePictureCardPreview(file)"
              >
                <i class="el-icon-zoom-in"></i>
              </span>
              <span
                v-if="!disabled"
                class="el-upload-list__item-delete"
                @click="handleDownload(file)"
              >
                <i class="el-icon-download"></i>
              </span>
              <span
                v-if="!disabled"
                class="el-upload-list__item-delete"
                @click="handleRemove(file)"
              >
                <i class="el-icon-delete"></i>
              </span>
            </span>
          </div>
        </el-upload>
        <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="dialogImageUrl" alt="" />
        </el-dialog>
        <span>只能上上传jpg/png文件，切不超过500kb</span>
      </div>
    </div>
    <div class="msglist">
      <div class="left">课程状态</div>
      <div class="right">
        <el-switch
          v-model="value1"
          active-text="上架"
          inactive-text="下架"
        >
        </el-switch>
      </div>
    </div>
    <div class="msglist">
      <div class="left">课程分类</div>
      <div class="right">
        <el-select v-model="value" placeholder="请选择" @change="mychange">
          <el-option
            v-for="item in data"
            :key="item.id"
            :label="item.leftTitle"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </div>
    </div>
    <div class="msglist">
      <div class="left">课程简介</div>
      <div class="right">
        <el-input
          type="textarea"
          :rows="2"
          placeholder="请输入内容"
          v-model="textarea"
        >
        </el-input>
      </div>
    </div>
    <div class="msglist">
      <div class="left">课程目录</div>
      <div class="right">
        <el-input
          type="textarea"
          autosize
          placeholder="请输入内容"
          v-model="textarea1"
        >
        </el-input>
      </div>
    </div>
    <div class="bottombtn">
      <el-button @click="subscribe" type="success">立即添加</el-button>
      <el-button @click="openset">取消</el-button>
    </div>
  </div>
</template>

<script>
// import a from './a'; // 引入组件
export default {
  name: "",
  data() {
    return {
      msg: "测试",
      course: "",
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false,
      value: "",
      value1: true,
      textarea: "",
      data: [],
     
      textarea: "",
      textarea1: "",
    };
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created() {},
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted() {
    this.getdata();
  },
  // Vue方法定义
  methods: {
    async getdata() {
      this.data = await this.$axios
        .get("/api/answer/curriculum")
        .then((res) => {
          return res.data;
        });
     
    },
    openset() {
      this.$emit("openset", true);
    },
    handleRemove(file) {
  
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleDownload(file) {
     
    },
    // 提交
    subscribe() {
      let index = this.data.findIndex((item) => {
        return item.id === this.value;
      });
      let data = {
        cid: "",
        classTitle: this.course,
        classImg:
          "https://wx1.sinaimg.cn/mw2000/006WxrJMly1gvu2ppf3cgj30ad04gdia.jpg",
        classBanner: [
          "https://wx1.sinaimg.cn/mw2000/006WxrJMly1gvu2ppf3cgj30ad04gdia.jpg",
          "https://wx2.sinaimg.cn/mw2000/006WxrJMly1gvu2pppl3rj30ad04ggo7.jpg",
          "https://wx4.sinaimg.cn/mw2000/006WxrJMly1gvu2pq8023j307o03adh6.jpg",
          "https://tse1-mm.cn.bing.net/th/id/OIP-C.v-KUsM4jsUIbmGXNujaJTQEyDM?w=227&h=180&c=7&r=0&o=5&pid=1.7",
          "https://tse2-mm.cn.bing.net/th/id/OIP-C.m5Qlhr6FalEZv3pfMRnlCQHaLE?w=120&h=180&c=7&r=0&o=5&pid=1.7",
          "https://tse3-mm.cn.bing.net/th/id/OIP-C.M0cNLQK2siZEzt-Z31jICwHaEK?w=276&h=180&c=7&r=0&o=5&pid=1.7",
        ],
        classPrice: "168",
         statebar: this.value1?"0":"1",
        introduce: this.textarea,
        jiNeng:this.data[index].leftTitle,
        personnum: Math.floor(Math.random() * 200 + 200),
        seePeople: "1.5",
        shopping: Math.floor(Math.random() * 1000),
        num: 0,
        zhifuState: 0,
        zhifu: 0,
        collect: 0,
        Peoplebuy: 4890,
      };
      this.$axios.post("/api/answer/add", { id: this.value, data });
      this.$emit("openset", true);
    },
    mychange() {
    },
  },
};
</script>

<style scoped>
/* @import url(''); 引入css类 */
.curriculusetadd {
  min-width: 1100px;
  margin: 20px;
  padding: 20px;
  background: white;
}
.opensetbtn {
  position: absolute;
  right: 44px;
  top: 78px;
  height: 30px;
  line-height: 5px;
}

/*  */
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.left {
  float: left;
  width: 100px;
}
.right {
  float: left;
  width: 50%;
}
.msglist {
  overflow: hidden;
  padding: 10px 10px;
}
.bottombtn {
  padding-left: 100px;
}
.bottombtn > button {
  margin-right: 25px;
}
</style>